package com.neusoft.mapper;

import com.neusoft.po.BusinessAdmin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BusinessAdminMapper {

    // 查询商家列表（模糊查询）
    @Select("SELECT * FROM business_admin " +
            "WHERE businessName LIKE CONCAT('%', #{businessName}, '%') " +
            "AND businessAddress LIKE CONCAT('%', #{businessAddress}, '%')")
    List<BusinessAdmin> ListBusiness(@Param("businessName") String businessName,
                                     @Param("businessAddress") String businessAddress);

    // 保存商家信息
    @Insert("INSERT INTO business_admin VALUES (#{businessId}, #{businessName}, #{password}, '默认地址', " +
            "'默认介绍', '15.00', '3.00', '')")
    int saveBusiness(BusinessAdmin business);

    // 删除商家信息
    @Delete("DELETE FROM business_admin WHERE businessId = #{businessId}")
    int removeBusiness(@Param("businessId") int businessId);

    // 查询 ID 是否存在
    @Select("SELECT count(*) FROM business_admin WHERE businessId = #{businessId}")
    int getById(@Param("businessId") String businessId);

    // 根据 ID 和密码获取商家
    @Select("SELECT * FROM business_admin WHERE businessId = #{businessId} AND password = #{password}")
    BusinessAdmin getBusinessByIdByPass(@Param("businessId") Integer businessId,
                                        @Param("password") String password);

    // 根据 ID 获取商家
    @Select("SELECT * FROM business_admin WHERE businessId = #{businessId}")
    BusinessAdmin getBusinessById(@Param("businessId") Integer businessId);

    // 更新商家信息
    @Update("UPDATE business_admin SET password = #{password}, businessName = #{businessName}, " +
            "businessAddress = #{businessAddress}, businessExplain = #{businessExplain}, " +
            "starPrice = #{starPrice}, deliveryPrice = #{deliveryPrice}, businessImg = #{businessImg} " +
            "WHERE businessId = #{businessId}")
    int updateBusiness(@Param("businessId") Integer businessId,
                       @Param("password") String password,
                       @Param("businessName") String businessName,
                       @Param("businessAddress") String businessAddress,
                       @Param("businessExplain") String businessExplain,
                       @Param("starPrice") Double starPrice,
                       @Param("deliveryPrice") Double deliveryPrice,
                       @Param("businessImg") String businessImg);

    // 根据 ID 和密码更新商家密码
    @Update("UPDATE business_admin SET password = #{password} WHERE businessId = #{businessId}")
    int updateBusinessByPassword(@Param("businessId") Integer businessId,
                                 @Param("password") String password);
}
